<?php

namespace App\Repositories\Eloquent\Biz;


use Illuminate\Container\Container as App;
use App\Repositories\Eloquent\Repository;
use Illuminate\Support\Facades\Auth;
use DB;

class RecordRepository extends Repository
{

    function model()
    {
        return 'App\Models\Biz\Record';
    }
    
    /**
     * type 交易类型，对应summary->set
     * @param [type] $user     [description]
     * @param [type] $activity [description]
     * @param [type] $amount   [description]
     * @param [type] $type     [description]
     * @param [type] $flag     [description]
     */
    public function set($user, $activity, $amount, $type, $flag = FLAG_DEBIT)
    {
        $balance = $user->summary->points;
        
        $result = $this->create([
            'aid'       => $activity->id,
            'uid'       => $user->id,
            'account'   => $user->account,
            'tid'       => $user->id,
            'type'      => empty($type) ? $user->type : $type,
            'flag'      => $flag,
            'amount'    => $amount,
            'status'    => 1,
            'balance'   => ($flag == FLAG_DEBIT) ? $balance + $amount : $balance - $amount,            
            'date'      => time(),
        ]);

        return $result->balance;

    }    

}